//
//  BuyHeader.m
//  预购清单
//
//  Created by  on 2022/10/16.
//

#import "BuyHeader.h"
@interface BuyHeader()
@property (strong, nonatomic) IBOutlet UITextField *input;
@property (strong, nonatomic) IBOutlet UIButton *picBtn;
@end
@implementation BuyHeader

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(Prepay *)model{
    _model = model;
    UIImage *img = model.img ? [UIImage imageWithData:model.img] : [UIImage imageNamed:@"选择图片"];
    [self.picBtn setImage:img forState:UIControlStateNormal];
    self.input.text = model.money == 0 ? @"" : [NSString stringWithFormat:@"%.2f",model.money];
}
- (IBAction)actionForBtn:(UIButton *)sender {
    if (self.block) {
        self.block();
    }
}
#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (![string isEqualToString:@" "] && ![string isNumber]) {
        if (![string isEqualToString:@"."]) {
            return NO;
        }
        if ([textField.text containsString:@"."]) {
            return NO;
        }else{
            return YES;
        }
        return NO;
    }
    return YES;
}
- (void)textFieldDidChangeSelection:(UITextField *)textField{
    self.model.money = [textField.text floatValue];
}
@end
